<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>动态组件</title>
    <script src="scripts/jquery-3.4.1.min.js"></script>
    <script src="scripts/vue.js"></script>
</head>

<body>
    <div id="app">
        <div id="content">
            <component :is="com"></component>
        </div>

        <button @click="chooseConent(1)">首页</button>
        <button @click="chooseConent(2)">列表</button>
        <button @click="chooseConent(3)">新闻</button>
        <button @click="chooseConent(4)">我的</button>
    </div>
    <script>
        let indexcom = Vue.component('xlb-component-index', {
            // name:'index',
            template: '<h1>《首页》内容</h1>'
        })
        let listcom = Vue.component('xlb-component-list', {
            template: '<h1>《列表》内容</h1>'
        })
        let newscom = Vue.component('xlb-component-news', {
            template: '<h1>《新闻》内容</h1>'
        })
        let mecom = Vue.component('xlb-component-me', {
            template: '<h1>《我的》内容</h1>'
        })
        let app = new Vue({
            el: "#app",
            data: {
                com: indexcom
            },
            methods: {
                chooseConent: function (num) {
                    console.log(num)
                    console.log(this)
                    switch (num) {
                        case 1:
                            this.com = indexcom;
                            break;
                        case 2:
                            this.com = this.$options.components.listcom;
                            break;
                        case 3:
                            this.com = this.$options.components.newscom;
                            break;
                        case 4:
                            this.com = this.$options.components.mecom;
                            break;
                    }

                    //
                }
            },
            components: {
                //index:xlbindex
                indexcom, listcom, newscom, mecom
            }
        })
    </script>
</body>

</html>